package com.cyz.web.app.leetcode.lengthOfLastWord;

public class Client {


    public static void main(String[] args) {
        String s = "   fly me   to   the moon  ";
        int i = lengthOfLastWord(s);
        System.out.println(i);
    }

    public static int lengthOfLastWord(String s) {
        if (s == null) return 0;
        int size = 0;
        char c = ' ';
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) != c) {
                size++;
            } else if (size > 0) {
                return size;
            }
        }
        return size;
    }


}
